/*
 * Copyright 2012 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package be.free.ts.timesheet;

import be.free.ts.activity.Activity;
import be.free.ts.employee.Employee;
import be.free.ts.support.Builder;
import be.free.ts.support.IntervalBuilder;
import org.joda.time.DateTime;

import javax.inject.Inject;
import javax.inject.Provider;

/**
 * @author Christophe De Blende
 * @since 03/04/13
 */
public class TimesheetBuilder implements Builder<Timesheet> {

	private final Provider<Timesheet> timesheetProvider;

	private final Provider<IntervalBuilder> intervalBuilder;

	private DateTime startDateTime;

	private DateTime endDateTime;

	private Activity activity;

	private String description;

	private Employee employee;

	@Inject
	public TimesheetBuilder(Provider<Timesheet> timesheetProvider, Provider<IntervalBuilder> intervalBuilder) {
		this.timesheetProvider = timesheetProvider;
		this.intervalBuilder = intervalBuilder;
	}

	public TimesheetBuilder startDateTime(DateTime value) {
		startDateTime = value;
		return this;
	}

	public TimesheetBuilder endDateTime(DateTime value) {
		endDateTime = value;
		return this;
	}

	public TimesheetBuilder activity(Activity value) {
		activity = value;
		return this;
	}

	public TimesheetBuilder description(String value) {
		description = value;
		return this;
	}

	public TimesheetBuilder employee(Employee value) {
		employee = value;
		return this;
	}

	@Override
	public Timesheet build() {
		Timesheet timesheet = timesheetProvider.get();
		timesheet.setInterval(intervalBuilder.get()
				.startDateTime(startDateTime)
				.endDateTime(endDateTime)
				.build());
		timesheet.setActivity(activity);
		timesheet.setDescription(description);
		timesheet.setEmployee(employee);
		timesheet.setSubmittedDateTime(DateTime.now());
		return timesheet;
	}
}
